import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class NGuessNumberTest {
    int[] number = NGuessNumber.generateAnswer();
    int[] b = {1,2,3,4};
    int[] c = {1,2,3,4};
    @org.junit.jupiter.api.BeforeEach
    void setUp() {
    }

    @org.junit.jupiter.api.AfterEach
    void tearDown() {
    }

    @Test
    void generateAnswerText(){

        //测试是否四个数字
        assertEquals(4,number.length);
        //检查是否重复
        assertTrue(Repeat_or_not());
        //检查数是否都在0~9之间
        assertTrue(pd());
    }

    @Test
    void getPlayerInputText(){
        assertEquals(4,NGuessNumber.getPlayerInput(b).length);
    }

    @Test
    void compareGuessAnswerText(){
        assertTrue(compare());
    }

    @Test
    void isWinText(){
        assertTrue(isWintf());
    }

    boolean Repeat_or_not(){
        for (int i = 0 ; i <3; i ++){
            for (int j = i+1; j <4 ; j++){
                if (number[i] == number[j]){
                    return false;
                }
            }
        }
        return true;
    }
    boolean pd(){
        for (int i =0 ; i < number.length;i++){
            if( number[i]>9){
                return false;
            }

        }
        return true;

    }
    private boolean compare() {
        if (NGuessNumber.compareGuessAnswer(b,c).equals("猜对了")){
            return true;
        }
        return !NGuessNumber.compareGuessAnswer(b,c).contains("A");
    }
    public boolean isWintf() {
        return NGuessNumber.isWin(NGuessNumber.compareGuessAnswer(b,c));
    }
}